<html>
<head><meta charset="utf-8"><title>Multiple versions of the same file? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html">Multiple versions of the same file?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225436975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225436975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225436975">(Feb 07 2021 at 00:20)</a>:</h4>
<p>I tried figuring this out from the source code, but it seems a bit unclear whether rustc can handle multiple versions of the same file, for uses such as rust-analyzer, where the compilation results and internal data structures for one version are partially shared with another version. Or is everything thrown away after each compilation?</p>



<a name="225438554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225438554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225438554">(Feb 07 2021 at 01:08)</a>:</h4>
<p>Are you talking about incremental compilation?</p>



<a name="225438595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225438595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225438595">(Feb 07 2021 at 01:08)</a>:</h4>
<p><a href="https://rustc-dev-guide.rust-lang.org/query.html">https://rustc-dev-guide.rust-lang.org/query.html</a></p>



<a name="225439654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439654">(Feb 07 2021 at 01:35)</a>:</h4>
<p>Yes, but more specifically about how rustc is able to represent the file and point to spans in the file when it has multiple versions of the same file in flight. I'm looking for example at <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/enum.FileName.html"><code>FileName</code></a> which doesn't have what I would call a versioning system on its files, such as you can find in the LSP protocol for example. Or perhaps it uses virtual paths with a hash of some kind?</p>



<a name="225439708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439708">(Feb 07 2021 at 01:36)</a>:</h4>
<p>rust-analyzer works on an entire crate graph, while a rustc invocation is currently limited to building only a single crate (although it can load arbitrarily many other crates as dependencies)</p>
<p>rust-analyzer has a split between files (<code>FileId</code> for actual on-disk files, <code>HirFileId</code> for either real files or the results of macro expansions), and crates (<code>CrateId</code>, <code>DefMap</code>)</p>



<a name="225439717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439717">(Feb 07 2021 at 01:37)</a>:</h4>
<p>I'm not entirely sure what exactly you mean by "multiple versions" of the same file. Are you talking about applying different <code>#[cfg]</code>s to a file? Or about having 2 <code>mod</code>-declarations with the same <code>#[path]</code>?</p>



<a name="225439763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439763">(Feb 07 2021 at 01:38)</a>:</h4>
<p>As far as incremental compilation is concerned, files don't exist and only a single snapshot of a crate is ever stored on disk, so it can't run into problems here, I believe</p>



<a name="225439765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439765">(Feb 07 2021 at 01:39)</a>:</h4>
<p>I mean like if you use r-a to <code>cargo check</code> a crate, then make a change to the crate and <code>cargo check</code> again, ideally reusing most of the previous work (i.e. incremental compilation), meaning that you will have some spans pointing to outdated versions of a file</p>



<a name="225439772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439772">(Feb 07 2021 at 01:39)</a>:</h4>
<p>Oh I see, you don't ever check files that aren't on disk?</p>



<a name="225439821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439821">(Feb 07 2021 at 01:40)</a>:</h4>
<p>Cargo and rustc don't know about in-memory files when using rust-analyzer</p>



<a name="225439823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439823">(Feb 07 2021 at 01:40)</a>:</h4>
<p>They do when using RLS, because that implements its own rustc file loader that uses its VFS</p>



<a name="225439825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439825">(Feb 07 2021 at 01:41)</a>:</h4>
<p>So all the live feedback is 100% rust-analyzer code, not rustc?</p>



<a name="225439829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439829">(Feb 07 2021 at 01:41)</a>:</h4>
<p>yeah</p>



<a name="225439887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439887">(Feb 07 2021 at 01:43)</a>:</h4>
<p>But I don't really understand how this solves any issues with spans. I believe spans are currently a (rather volatile) component of the query system, so any change in spans results in recomputation of the queries that access the span data.</p>



<a name="225439938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439938">(Feb 07 2021 at 01:45)</a>:</h4>
<p>The reason I ask is because I'm writing a similar kind of language server and I sometimes have the problem that spans are byte positions into a file that no longer matches the actual file on disk or the file in the user's editor so you can get drift or just completely wrong positions. I was curious what rustc et al are doing to address this kind of issue</p>



<a name="225439981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439981">(Feb 07 2021 at 01:46)</a>:</h4>
<p>Ah, I see</p>



<a name="225439987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225439987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225439987">(Feb 07 2021 at 01:47)</a>:</h4>
<p>rust-analyzer will not update <code>cargo check</code> diagnostics to point to the right line when you type</p>



<a name="225440033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Multiple%20versions%20of%20the%20same%20file%3F/near/225440033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Multiple.20versions.20of.20the.20same.20file.3F.html#225440033">(Feb 07 2021 at 01:48)</a>:</h4>
<p>this is something it should probably start doing at some point, because <code>cargo check</code> can only be re-run on save, so you currently end up with diagnostics all over the place (and worse, suggestions that modify the wrong place)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>